# 读取图片,做相应预处理
img = Image.open('./data/house.jpg').convert('L')
img = np.array(img).astype('float32')
x = img.reshape(1,1,img.shape[0], img.shape[1]) 
#(1,1,280,376)[N,C,H,W]
x = torch.Tensor(x) #(1,1,282,378) # 输入 [N, C, H, W] 
# 创建初始化参数
# 卷积核w,shape为 (out_channels, in_channels,Kh, Kw)
w = np.ones([1, 1, 5, 5], dtype = 'float32')/25
w = torch.Tensor(w)
conv = nn.Conv2d(in_channels=1,
                    out_channels=1,
                    kernel_size=(5,5),
                    stride = 1)
conv.weight = nn.Parameter(w)  # 赋值
# 计算
y = conv(x)
out = y.data
#查看 y形状,输出通道数为 1,out_channels=1一致
print(out.shape)#(1, 1,278, 374) 
